from flask import Flask
from dotenv import load_dotenv
from models.models import db
import os
import logging
from routes.main_route import main_bp
from routes.auth_route import auth_bp

load_dotenv()

app = Flask(__name__)

#import config
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False    #不关闭会默认记录对象的修改，造成内存开销
app.config['JWT_SECRET_KEY'] = os.getenv('JWT_SECRET_KEY')

#init db
db.init_app(app)

#register blueprint
app.register_blueprint(main_bp)
app.register_blueprint(auth_bp)
for rule in app.url_map.iter_rules():
    print(rule)

#set log
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


if __name__ == '__main__':
    logger.info('Flask启动')
    app.run(debug=True,host='0.0.0.0',port=5000)